Index
Debugging


Debugging is finding and fixing bugs in our code.

A debugger (tool that helps us find bugs) can be as useful as our code editor.

Here is a video that will help you get started debugging:


Steps:


Debugging Example (in Web Browser)


Setup


First download this file... and copy the contained files into a new working directory.

You will find these files:


Open Browser


Let's open up a web browser on the .html file

We next do the following steps:


Find and Fix Bug


Find Bug
The web browser has helpfully pointed us to the line number of the bug.

We open up the .js file in a plain text editor.

On that line we see a typo.
let foo = new FooWithBugs();
prn(foo.toString());
//prn(foo.getHello_BIG_TYPO_HERE());
Fix Bug
We fix the typo.

And save the file.
let foo = new FooWithBugs();
prn(foo.toString());
//prn(foo.getHello());
We re-open or re-activate the browser.

If re-activating, we do the "refresh" action (F5 in some browsers).

And we have the expected output (the code ran).
I am Foo
Hello
Goodbye
It is easy to have several bugs lurking in the code.

The easiest approach, when debugging with a web browser, is usually to fix one bug like in the previous steps, and then repeat the steps. It is relatively fast because you can keep your editors open and just refresh (on the .html side) as needed.
let foo = new FooWithBugs();
prn(foo.toStringXXXX());
prn(foo.toStringYYYY());

Student Debugging Examples


See student examples here:


Web Browser Flakiness


On occasion, web browsers can be fussy (they have gotten better). If the browser is acting odd (e.g. not showing anything on console, etc) try to refresh. Also try "Clear Browsing Data". And then restart it.